#include <iostream>
#include <string>

using namespace std;

class Solution
{
public:
    char repeatedCharacter(string s)
    {
        int n = s.size();
        int len = n;
        char ret;
        char cur;
        int left = 0;
        int right = 0;

        int i = 0;
        while (i < n)
        {
            cur = s[i];
            right = s.find(cur, i + 1);
            if (right != string::npos)
            {
                int tlen = right - left;
                if (tlen <= len)
                {
                    len = tlen;
                    ret = cur;
                }
            }
            else
            {
                i++;
                continue;
            }

            i++;
        }

        return ret;
    }
};

int main()
{
    Solution slo;
    string s = "abccbaacz";
    slo.repeatedCharacter(s);

	return 0;
} 